@extends('layouts.default')

@section('title', '论著发表')

@push('scripts')
<script>
    var filters = {};
    var per_page = 10;
    var totalNum = 0;
    layui.use(['layer','form','table','laytpl','laydate','element','laypage'], function(){
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var laytpl = layui.laytpl;
        var laydate = layui.laydate;
        var element = layui.element;
        var laypage = layui.laypage;
        var lay_id = $("#tab-1").children('.layui-this').attr('lay-id');
        var materials_date = "{{request()->get('materials_date',0)}}";
        var key = "{{request()->get('key','')}}";


        if(lay_id == 1){
            getList(1,per_page,128);
        }else if(lay_id == 2){
            getList2(1,per_page,129);
        }

        laydate.render({
            elem: '#begin-date'
            ,type: 'date'
        });

      
        // 获取页面数据
        function getList(page, limit,publish_type) {
            if ($.isEmptyObject(filters)){
                let param = form.val("qryForm");
                filters = param;
            }
            
            var para = {
                "page": page,
                "json_search": {pubications_publish_type:publish_type},
                "limit": limit,
                "is_log":false,
                "form_key": 'TEARRESEARCH_PUBLISH_TABLE',
                
            };
            let whereStr = ''; 
            if(key.length > 0){
                switch (key) { 
                    case "0": 
                        whereStr = " `activity_info`.is_awarded = 1 and ( JSON_CONTAINS(`activity_info`.level,JSON_OBJECT('optionId', 106)) or JSON_CONTAINS(`activity_info`.level,JSON_OBJECT('optionId', 107)) ) ";
                    break; 
                    case "1": 
                        whereStr = " `activity_info`.begin_date <> '' and ( JSON_CONTAINS(`activity_info`.level,JSON_OBJECT('optionId', 106)) or JSON_CONTAINS(`activity_info`.level,JSON_OBJECT('optionId', 107)) ) ";
                    break; 
                    case "2": 
                        whereStr = " `activity_info`.is_awarded = 1 and JSON_CONTAINS(`activity_info`.level,JSON_OBJECT('optionId', 108)) ";
                    break; 
                    case "3": 
                        whereStr = " `activity_info`.begin_date <> '' and JSON_CONTAINS(`activity_info`.level,JSON_OBJECT('optionId', 108)) ";
                    break; 
                    case "4": 
                        whereStr = " `activity_info`.is_wsjl = 1 and JSON_CONTAINS(`activity_info`.level,JSON_OBJECT('optionId', 108)) ";
                    break;     
                }
            } 
            Object.assign(para, {"search": {'status':'PASS','materials_date': materials_date,whereStr:whereStr}});	
            getActivityList(para, function(res){
                if(res.code === 1) {
                    if(totalNum != res.total) {
                        totalNum = res.total;
                        per_page = res.limit;
                        renderPageBar(page,per_page)
                    }

                    table.render({
                        data: res.data,
                        elem: '#tablelist',
                        toolbar: '#toolbarHead', //开启头部工具栏，并为其绑定左侧模板
                        defaultToolbar: [],
                        cellMinWidth: 80, //全局定义常规单元格的最小宽度，layui 2.2.1 新增
                        limit: res.data.limit,
                        id:"tableIns",
                        skin: 'nob',
                        cols: [[
                            {type: 'checkbox', fixed: 'left'},
                            {field: 'term_name', title: '学年学期', align: 'left', templet: function(d) {
                                let termName = d.data_version_id ? d.term.title : '-';
                                return d.data_version_name ? d.data_version_name : termName;
                            }},
                            {field: 'name', title: '名称', align: 'center'},
                            {field: '', title: '类型', align: 'center', templet: function(d) {
                                return d.publish_type_set[0]['selectValue'];
                            }},
                            {field: 'begin_date', title: '发表日期', align: 'center'},
                            {field: 'activity_category_name', title: '类别', align: 'center', templet: function(d) {
                                switch(d.activity_category) {
                                    case 'TEARRESEARCH_PUBLISH_TABLE':
                                        return '教学';
                                        break;
                                    case 'EW_PAPER_PUBLISH_TABLE':
                                        return '教育';
                                        break;
                                    default:
                                        return '-';
                                        break;
                                }
                            }},
                            {field: 'level', title: '级别', align: 'center', templet: function(d) {
                                return d.level_array.length > 0 ? d.level_array[0].selectValue : '-';
                            }},
                            {field: 'creator', title: '创建人', align: 'center', templet: function(d) {
                                return d.creator ? d.creator.nickname : '-';
                            }},
                            {field: 'status_name', title: '状态', align: 'center', templet: function(d) {
                                switch(d.status) {
                                    case 'REVOKE':
                                        return '撤回';
                                        break;
                                    case 'FILL_IN':
                                        return '未提交';
                                        break;
                                    case 'REVIEW':
                                        return '待审核';
                                        break;
                                    case 'REVIEW_FAIL':
                                        return '已驳回';
                                        break;
                                    case 'PASS':
                                        return '审核通过';
                                        break;
                                    default:
                                        return '-';
                                        break;
                                }
                            }},
                            {title: '操作', width: '20%', align: 'center', toolbar: '#opDemo', fixed:'right'}
                        ]],                      
                        done: function(res, curr, count) {
                            setBtnPermission();  
                            curr_page = page;
                        },
                        page: false,
                        loading: true
                    });

                    // 渲染页面
                    function renderPageBar(page,limit) {
                        laypage.render({
                            elem: 'pageBar',
                            count: totalNum, //数据总数，从服务端得到
                            curr: page,
                            first: '第一页',
                            last: '最后一页',
                            limit:limit,
                            layout: ['limit','count', 'prev', 'page', 'next', 'skip'],
                            jump: function(obj, first) {
                                //首次不执行
                                if(!first) {
                                    layer.closeAll();
                                    getList(obj.curr,obj.limit,128)
                                }
                            }
                        });
                    }
                } else {
                    layer.msg(res.msg, {time: 2000, icon: 5});
                }
            });
        }

        // 获取页面数据
        function getList2(page, limit,publish_type) {
            if ($.isEmptyObject(filters)){
                let param = form.val("qryForm");
                filters = param;
            }
            
            var para = {
                "page": page,
                "json_search": {pubications_publish_type:publish_type},
                "limit": limit,
                "is_log":false,
                "form_key": 'TEARRESEARCH_PUBLISH_TABLE',
                
            };
            let whereStr = ''; 
            if(key.length > 0){
                switch (key) { 
                    case "0": 
                        whereStr = " `activity_info`.date <> '' and ( JSON_CONTAINS(`activity_info`.level,JSON_OBJECT('optionId', 106)) or JSON_CONTAINS(`activity_info`.level,JSON_OBJECT('optionId', 107)) ) ";
                    break; 
                    case "1": 
                        whereStr = " `activity_info`.begin_date <> '' and ( JSON_CONTAINS(`activity_info`.level,JSON_OBJECT('optionId', 106)) or JSON_CONTAINS(`activity_info`.level,JSON_OBJECT('optionId', 107)) ) ";
                    break; 
                    case "2": 
                        whereStr = " `activity_info`.date <> '' and JSON_CONTAINS(`activity_info`.level,JSON_OBJECT('optionId', 108)) ";
                    break; 
                    case "3": 
                        whereStr = " `activity_info`.begin_date <> '' and JSON_CONTAINS(`activity_info`.level,JSON_OBJECT('optionId', 108)) ";
                    break; 
                    case "4": 
                        whereStr = " JSON_CONTAINS(`activity_info`.level,JSON_OBJECT('optionId', 99999)) "; //不显示
                    break;     
                }
            } 
            Object.assign(para, {"search": {'status':'PASS','materials_date': materials_date,whereStr:whereStr}});	
            getActivityList(para, function(res){
                if(res.code === 1) {
                    if(totalNum != res.total) {
                        totalNum = res.total;
                        per_page = res.limit;
                        renderPageBar(page,per_page)
                    }

                    table.render({
                        data: res.data,
                        elem: '#tablelist2',
                        toolbar: '#toolbarHead2', //开启头部工具栏，并为其绑定左侧模板
                        defaultToolbar: [],
                        cellMinWidth: 80, //全局定义常规单元格的最小宽度，layui 2.2.1 新增
                        limit: res.data.limit,
                        id:"tableIns2",
                        skin: 'nob',
                        cols: [[
                            {type: 'checkbox', fixed: 'left'},
                            {field: 'term_name', title: '学年学期', align: 'left', templet: function(d) {
                                let termName = d.data_version_id ? d.term.title : '-';
                                return d.data_version_name ? d.data_version_name : termName;
                            }},
                            {field: 'name', title: '名称', align: 'center'},
                            {field: '', title: '类型', align: 'center', templet: function(d) {
                                return d.publish_type_set[0]['selectValue'];
                            }},
                            {field: 'begin_date', title: '发表日期', align: 'center'},
                            {field: 'activity_category_name', title: '类别', align: 'center', templet: function(d) {
                                switch(d.activity_category) {
                                    case 'TEARRESEARCH_PUBLISH_TABLE':
                                        return '教学';
                                        break;
                                    case 'EW_PAPER_PUBLISH_TABLE':
                                        return '教育';
                                        break;
                                    default:
                                        return '-';
                                        break;
                                }
                            }},
                            {field: 'level', title: '级别', align: 'center', templet: function(d) {
                                return d.level_array.length > 0 ? d.level_array[0].selectValue : '-';
                            }},
                            {field: 'creator', title: '创建人', align: 'center', templet: function(d) {
                                return d.creator ? d.creator.nickname : '-';
                            }},
                            {field: 'status_name', title: '状态', align: 'center', templet: function(d) {
                                switch(d.status) {
                                    case 'REVOKE':
                                        return '撤回';
                                        break;
                                    case 'FILL_IN':
                                        return '未提交';
                                        break;
                                    case 'REVIEW':
                                        return '待审核';
                                        break;
                                    case 'REVIEW_FAIL':
                                        return '已驳回';
                                        break;
                                    case 'PASS':
                                        return '审核通过';
                                        break;
                                    default:
                                        return '-';
                                        break;
                                }
                            }},
                            {title: '操作', width: '20%', align: 'center', toolbar: '#opDemo2', fixed:'right'}
                        ]],                      
                        done: function(res, curr, count) {
                            setBtnPermission();  
                            curr_page = page;
                        },
                        page: false,
                        loading: true
                    });

                    // 渲染页面
                    function renderPageBar(page,limit) {
                        laypage.render({
                            elem: 'pageBar2',
                            count: totalNum, //数据总数，从服务端得到
                            curr: page,
                            first: '第一页',
                            last: '最后一页',
                            limit:limit,
                            layout: ['limit','count', 'prev', 'page', 'next', 'skip'],
                            jump: function(obj, first) {
                                //首次不执行
                                if(!first) {
                                    layer.closeAll();
                                    getList(obj.curr,obj.limit,129)
                                }
                            }
                        });
                    }
                } else {
                    layer.msg(res.msg, {time: 2000, icon: 5});
                }
            });
        }
        

        //表格头工具栏事件
        table.on('toolbar(tablelsit)', function(obj){
            switch(obj.event){
                case 'add':
                    
                break;
            };
        });

        element.on('tab(docDemoTabBrief)', function(){
            lay_id =  this.getAttribute('lay-id');
            if(lay_id == 1){
                getList(1,per_page,128);
            }else if(lay_id == 2){
                getList2(1,per_page,129);
            }
        });


        $('#click-checkbox').click(function(){           
            if(lay_id == 1){
                var checkStatus = table.checkStatus('tableIns');
            }else if(lay_id == 2){
                var checkStatus = table.checkStatus('tableIns2');
            }
            window.parent.checkboxdata = checkStatus;     
        })

    });
</script>
<script type="text/html" id="opDemo">
        <a btnPermission="230" class="layui-btn layui-btn-primary layui-border-orange layui-btn-xs" href="{{route('paper.infoView')}}?id=@{{d.id}}">查看</a>
    </script>
    <script type="text/html" id="opDemo2">
        <a btnPermission="235" class="layui-btn layui-btn-primary layui-border-orange layui-btn-xs" href="{{route('treatise.infoView')}}?id=@{{d.id}}">查看</a>
    </script>
    <script type="text/html" id="toolbarHead">
        <div class="list-head">
            <h3>论文发表列表</h3>
            <div class="layui-btn-container list-opt-btns">
                <a btnPermission="231" class="layui-btn layui-btn-normal" href="{{route('paper.addView')}}" id="addBtn"> + 新增 </a>
            </div>
        </div>
    </script>
    <script type="text/html" id="toolbarHead2">
        <div class="list-head">
            <h3>论著发表列表</h3>
            <div class="layui-btn-container list-opt-btns">
                <a btnPermission="236" class="layui-btn layui-btn-normal" href="{{route('treatise.addView')}}" id="addBtn"> + 新增 </a>
            </div>
        </div>
    </script>
@endpush

@section('content')
<style>
    
</style>


<div class="layui-card">
    
    
<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
      <ul class="layui-tab-title" id="tab-1">
        <li class="layui-this" lay-id="1" >论文发表</li>
        <li lay-id="2">论著发表</li>
      </ul>
      <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
            <div class="layui-card">
                <div class="layui-card-body">
                    <table class="layui-table" id="tablelist" lay-filter="tablelist"></table>
                    <div class="pagebarbox" style="text-align: end"><div id="pageBar" class="pagebar"></div></div>
                </div>
            </div>
        </div>
        <div class="layui-tab-item">
            <div class="layui-card">
                <div class="layui-card-body">
                    <table class="layui-table" id="tablelist2" lay-filter="tablelist2" ></table>
                    <div class="pagebarbox" style="text-align: end"><div id="pageBar2" class="pagebar2"></div></div>
                </div>
            </div>
        </div>
      </div>
    </div>

    
</div>
<button style="display:none" id="click-checkbox" ></button>
@endsection
